unit uInteressado;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uPai, StdCtrls, DB, DBCtrls, Buttons, ExtCtrls, ComCtrls, Mask,
  FacDbEdit, XPMenu;

type
  TfInteressado = class(TfPai)
    fInteressado: TLabel;
    Label10: TLabel;
    Label9: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label5: TLabel;
    Label4: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label12: TLabel;
    BitBtn1: TBitBtn;
    FacDBEdit1: TFacDBEdit;
    FacDBEdit2: TFacDBEdit;
    FacDBEdit3: TFacDBEdit;
    FacDBEdit4: TFacDBEdit;
    FacDBEdit5: TFacDBEdit;
    FacDBEdit6: TFacDBEdit;
    FacDBEdit7: TFacDBEdit;
    FacDBEdit8: TFacDBEdit;
    FacDBEdit9: TFacDBEdit;
    FacDBEdit28: TFacDBEdit;
    Label15: TLabel;
    Label16: TLabel;
    FacDBEdit11: TFacDBEdit;
    FacDBEdit12: TFacDBEdit;
    GroupBox1: TGroupBox;
    DBComboBox3: TDBComboBox;
    Label13: TLabel;
    dbImovel: TDBComboBox;
    Label1: TLabel;
    DBComboBox1: TDBComboBox;
    Label11: TLabel;
    DBEdit12: TDBEdit;
    Label17: TLabel;
    DBComboBox2: TDBComboBox;
    Label18: TLabel;
    Label19: TLabel;
    FacDBEdit10: TFacDBEdit;
    Label20: TLabel;
    FacDBEdit13: TFacDBEdit;
    Label21: TLabel;
    FacDBEdit14: TFacDBEdit;
    Label22: TLabel;
    FacDBEdit15: TFacDBEdit;
    Label23: TLabel;
    FacDBEdit16: TFacDBEdit;
    Label14: TLabel;
    FacDBEdit17: TFacDBEdit;
    Label24: TLabel;
    DBMemo1: TDBMemo;
    Label25: TLabel;
    XPMenu1: TXPMenu;
    cbRua1: TComboBox;
    cbBairro1: TComboBox;
    cbCidade1: TComboBox;
    procedure btnIncluirClick(Sender: TObject);
    procedure btnProcurarClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btngravarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fInteressado: TfInteressado;

implementation

uses UDM, uProcurar;

{$R *.dfm}

procedure TfInteressado.btnIncluirClick(Sender: TObject);
begin
  inherited;
  dm.cds_interessadoDATA_CADASTRO.AsDateTime := Now;
  facDbEdit1.SetFocus;
end;

procedure TfInteressado.btnProcurarClick(Sender: TObject);
begin
  inherited;
  fProcurar:=TfProcurar.Create(self,dm.proc_interessados);
  try
   formHondeEstou := 'Interessados';
   FProcurar.RadioGroup1.Visible := True;
   FProcurar.RadioGroup1.ItemIndex := 0;
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'NOME';
   if fProcurar.ShowModal=mrOk then
   begin
    Dm.cds_interessado.Close;
    dm.cds_interessado.Params[0].Clear;
    Dm.cds_interessado.Params[0].AsInteger:=dm.proc_interessadosCOD_INTERESSADO.AsInteger;
    Dm.cds_interessado.Open;
    cbRua1.Text := dm.proc_interessadosRUAIMOVEL.AsString;
    cbBairro1.Text := dm.proc_interessadosBAIRROIMOVEL.AsString;
    cbCidade1.Text := dm.proc_interessadosCIDADEIMOVEL.AsString;
   end;
   finally
    dm.proc_interessados.Close;
    formHondeEstou := '';
    fProcurar.Free;
   end;
end;

procedure TfInteressado.BitBtn1Click(Sender: TObject);
begin
  inherited;
 formHondeEstou := 'Proprietario';
 if (dm.cds_interessado.State in [dsInsert, dsEdit, dsbrowse]) then
 begin
  fProcurar:=TfProcurar.Create(self,dm.proc_cep);
  try
   fProcurar.TIPO := 'CEP';
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'RUA';
   fProcurar.btnIncluir.Visible := true;
   if fProcurar.ShowModal=mrOk then
   begin
    dm.cds_interessadoCOD_ENDERECO.AsInteger := dm.proc_cepCOD_CEP.AsInteger;
    dm.cds_interessadoRUA.AsString := dm.proc_cepRUA.AsString;
    FacDBEdit2.SetFocus;
    end;
   finally
    dm.proc_cep.Close;
    fProcurar.TIPO := '';
    formHondeEstou := '';
    fProcurar.Free;
   end;
 end;

end;

procedure TfInteressado.FormShow(Sender: TObject);
begin
  inherited;

  if (dm.cds_cep.Active) then
      dm.cds_cep.Close;
  dm.cds_cep.Params[0].Clear;
  dm.cds_cep.Params[1].AsInteger := 9999999;
  dm.cds_cep.Open;
  dm.cds_cep.First;
  while not dm.cds_cep.Eof do
  begin
     cbRua1.Items.Add(dm.cds_cepRUA.AsString);
     dm.cds_cep.Next;
  end;
  dm.cds_cep.Close;
  if (not dm.cds_bairro.Active) then
      dm.cds_bairro.Open;
  dm.cds_bairro.First;
  while not dm.cds_bairro.Eof do
  begin
     cbBairro1.Items.Add(dm.cds_bairroBAIRRO.AsString);
     dm.cds_bairro.Next;
  end;
  dm.cds_bairro.Close;

  if (not dm.cds_cidade.Active) then
      dm.cds_cidade.Open;
  dm.cds_cidade.First;
  while not dm.cds_cidade.Eof do
  begin
     cbCidade1.Items.Add(dm.cds_cidadeCIDADE.AsString);
     dm.cds_cidade.Next;
  end;
  dm.cds_cidade.Close;
end;

procedure TfInteressado.btngravarClick(Sender: TObject);
begin
    if cbRua1.Text <> '' then
      DM.cds_interessadoRUAIMOVEL.AsString := cbRua1.Text;
    if cbBairro1.Text <> '' then
      DM.cds_interessadoBAIRROIMOVEL.AsString := cbBairro1.Text;
    if cbCidade1.Text <> '' then
      DM.cds_interessadoCIDADEIMOVEL.AsString := cbCidade1.Text;
  inherited;

end;

end.
